//
//  UIBarButtonItem+Extensions.swift
//  LspSwiftFinayTest
//
//  Created by lsp's mac pro on 2018/3/28.
//  Copyright © 2018年 lsp's mac pro. All rights reserved.
//

import UIKit
/*
 convenience:便利，使用convenience修饰的构造函数叫做便利构造函数
 便利构造函数通常用在对系统的类进行构造函数的扩充时使用。
 便利构造函数的特点：
 1、便利构造函数通常都是写在extension里面
 2、便利函数init前面需要加载convenience
 3、在便利构造函数中需要明确的调用self.init()
 
 */
extension UIBarButtonItem {
    
    /// 创建UIBarButtonItme
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: fontSize 默认16
    ///   - target: target
    ///   - action: action
    ///   - isBack:是否返回按钮
    convenience init (title:String,fontSize:CGFloat=16,target:AnyObject?,action:Selector,isBack:Bool=false){
        
        let btn : UIButton=UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        btn.addTarget(target, action: action, for: .touchUpInside)
        
        if isBack==true {
            btn.setImage(UIImage(named:"navigationbar_back_withtext"), for: UIControlState(rawValue:0))
            btn.setImage(UIImage(named:"navigationbar_back_withtext_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        //实例化UIBarButtonItme
        self.init(customView: btn)
    }
    
}
